#!/bin/bash
swap_size=$(free -h |grep Swap | awk '{print $2}')
if [[ ${swap_size} == "0B" ]]; then
    exit 1;
fi

lld_swap_log=/home/myzabbix/zabbix.lld.swap.log

if egrep -c 'Red Hat|EulerOS' /proc/version &> /dev/null; then   # CentOS7或RHEL7或EulerOS的单位总是KB
    awk -v c="$1" '{if ($2==c) print $1; }' ${lld_swap_log}
elif grep -c SUSE /proc/version &> /dev/null; then   # SUSE11的单位是智能显示的，如3.5g,400m,不带单位即是KB
    awk -v c="$1" '{if ($2==c) {
        if($1 ~ /g$/){
            sub(/g$/,"",$1); print $1*1024*1024;
        }else if($1 ~ /m$/){
            sub(/m$/,"",$1); print $1*1024;
        }else{
            print $1;
        }
    }}' ${lld_swap_log}
else
    echo 0;
fi
